package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUIActionGroupRelateDAO;
import com.ourteam.product.ui.dao.ProductUIActionGroupRelate;
import com.ourteam.product.ui.dao.ProductUIActionGroupRelateDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:16 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUIActionGroupRelateDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUIActionGroupRelateDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        ActionGroupId,
        RelatedActionId,
        Handler,
        Icon,
        LabelText,
        LabelKey,
        ConfirmInfo,
        ConfirmInfoKey,
        LastModifyUser,
        LastModifyTime,
        SortIndex,
        Status,
        Remarks,
        VisibleScript,
        MenuListId,
        DisableScript,
        Style,
        ActionGroupCode,
        ActionCode,
        ActionType,
        ListCode
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.ActionGroupId,
        _DataObjectProperty.RelatedActionId,
        _DataObjectProperty.Handler,
        _DataObjectProperty.Icon,
        _DataObjectProperty.LabelText,
        _DataObjectProperty.LabelKey,
        _DataObjectProperty.ConfirmInfo,
        _DataObjectProperty.ConfirmInfoKey,
        _DataObjectProperty.LastModifyUser,
        _DataObjectProperty.LastModifyTime,
        _DataObjectProperty.SortIndex,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.VisibleScript,
        _DataObjectProperty.MenuListId,
        _DataObjectProperty.DisableScript,
        _DataObjectProperty.Style,
        _DataObjectProperty.ActionGroupCode,
        _DataObjectProperty.ActionCode,
        _DataObjectProperty.ActionType,
        _DataObjectProperty.ListCode
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUIActionGroupRelate, ProductUIActionGroupRelateDAOQueryBean>
      daoHelper;

  public AbstractProductUIActionGroupRelateDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<
            ProductUIActionGroupRelate, ProductUIActionGroupRelateDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIActionGroupDAO.EntityName)
          .append(" PRODUCT_UI_ACTION_GROUP ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIActionGroupDAO.Id,
              com.ourteam.product.ui.dao.IProductUIActionGroupDAO.EntityName + ".",
              "PRODUCT_UI_ACTION_GROUP."));
      relatedJoinSQLBuffer.append(" = ").append(ActionGroupId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIActionDAO.EntityName)
          .append(" PRODUCT_UI_ACTION ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIActionDAO.Id,
              com.ourteam.product.ui.dao.IProductUIActionDAO.EntityName + ".",
              "PRODUCT_UI_ACTION."));
      relatedJoinSQLBuffer.append(" = ").append(RelatedActionId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIListDAO.EntityName)
          .append(" RELATED_LPWOWC_ProductUIList ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIListDAO.Id,
              com.ourteam.product.ui.dao.IProductUIListDAO.EntityName + ".",
              "RELATED_LPWOWC_ProductUIList."));
      relatedJoinSQLBuffer.append(" = ").append(MenuListId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUIActionGroupRelate
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUIActionGroupRelate aProductUIActionGroupRelate)
      throws Exception {

    if (aProductUIActionGroupRelate == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUIActionGroupRelate.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUIActionGroupRelate
   * @throws Exception
   */
  public void insert(ProductUIActionGroupRelate aProductUIActionGroupRelate) throws Exception {

    PropertyUtils.setProperty(
        aProductUIActionGroupRelate,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doInsert(aProductUIActionGroupRelate);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUIActionGroupRelate
   * @throws Exception
   */
  public void batchInsert(ProductUIActionGroupRelate[] aProductUIActionGroupRelates)
      throws Exception {

    super.doBatchInsert(aProductUIActionGroupRelates);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUIActionGroupRelateDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUIActionGroupRelate aProductUIActionGroupRelate) throws Exception {

    delete(aProductUIActionGroupRelate.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUIActionGroupRelate
   * @throws Exception
   */
  public void update(ProductUIActionGroupRelate aProductUIActionGroupRelate) throws Exception {

    PropertyUtils.setProperty(
        aProductUIActionGroupRelate,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    if (aProductUIActionGroupRelate.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUIActionGroupRelate);

    ProductUIActionGroupRelate tempObj = findById(aProductUIActionGroupRelate.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUIActionGroupRelate, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUIActionGroupRelates[]
   * @throws Exception
   */
  public void batchUpdate(ProductUIActionGroupRelate[] aProductUIActionGroupRelates)
      throws Exception {

    super.doBatchUpdate(aProductUIActionGroupRelates);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUIActionGroupRelate
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      ProductUIActionGroupRelate aProductUIActionGroupRelate,
      ProductUIActionGroupRelateDAOQueryBean aQueryBean)
      throws Exception {

    PropertyUtils.setProperty(
        aProductUIActionGroupRelate,
        _DataObjectProperty.LastModifyTime,
        new java.sql.Timestamp(System.currentTimeMillis()));

    super.doUpdateByQuery(aProductUIActionGroupRelate, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUIActionGroupRelateDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUIActionGroupRelate aProductUIActionGroupRelate)
      throws Exception {

    if (aProductUIActionGroupRelate.getHandler() == null) {
      throw new Exception("The ProductUIActionGroupRelate.handler value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getIcon() == null) {
      throw new Exception("The ProductUIActionGroupRelate.icon value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getLabelText() == null) {
      throw new Exception("The ProductUIActionGroupRelate.labelText value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getLabelKey() == null) {
      throw new Exception("The ProductUIActionGroupRelate.labelKey value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getConfirmInfo() == null) {
      throw new Exception("The ProductUIActionGroupRelate.confirmInfo value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getConfirmInfoKey() == null) {
      throw new Exception("The ProductUIActionGroupRelate.confirmInfoKey value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getLastModifyUser() == null) {
      throw new Exception("The ProductUIActionGroupRelate.lastModifyUser value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getLastModifyTime() == null) {
      throw new Exception("The ProductUIActionGroupRelate.lastModifyTime value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getStatus() == null) {
      throw new Exception("The ProductUIActionGroupRelate.status value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getRemarks() == null) {
      throw new Exception("The ProductUIActionGroupRelate.remarks value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getActionGroupCode() == null) {
      throw new Exception("The ProductUIActionGroupRelate.actionGroupCode value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getActionCode() == null) {
      throw new Exception("The ProductUIActionGroupRelate.actionCode value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getActionType() == null) {
      throw new Exception("The ProductUIActionGroupRelate.actionType value is not allow NULL");
    }

    if (aProductUIActionGroupRelate.getStyle() == null) {
      throw new Exception("The ProductUIActionGroupRelate.style value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUIActionGroupRelate findById(final long id) throws Exception {

    ProductUIActionGroupRelateDAOQueryBean queryBean = new ProductUIActionGroupRelateDAOQueryBean();

    ProductUIActionGroupRelateDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUIActionGroupRelate[] ProductUIActionGroupRelates = query(queryBean);

    if (ProductUIActionGroupRelates.length == 0) {
      return null;
    } else {
      return ProductUIActionGroupRelates[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUIActionGroupRelate[]
   * @throws Exception
   */
  public ProductUIActionGroupRelate[] query(ProductUIActionGroupRelateDAOQueryBean queryBean)
      throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUIActionGroupRelateRowMapper());

    return (ProductUIActionGroupRelate[])
        result.toArray(new ProductUIActionGroupRelate[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUIActionGroupRelateDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUIActionGroupRelateDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      ProductUIActionGroupRelate[] aProductUIActionGroupRelates,
      ProductUIActionGroupRelateDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUIActionGroupRelates, queryBean);
  }

  public void synchronize(
      ProductUIActionGroupRelate[] aProductUIActionGroupRelates,
      ProductUIActionGroupRelateDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUIActionGroupRelate> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUIActionGroupRelates, queryBean, callBack);
  }

  public static class JdbcProductUIActionGroupRelateRowMapper
      implements RowMapper<ProductUIActionGroupRelate> {

    public ProductUIActionGroupRelate mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUIActionGroupRelate object = new ProductUIActionGroupRelate();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object actionGroupId = null;

        actionGroupId = resultSet.getObject(columnIndex++);

        object.setActionGroupIdNull(resultSet.getBoolean(columnIndex++));

        if (actionGroupId != null) {

          setBeanValue(object, _DataObjectProperty.ActionGroupId, actionGroupId);
        }

        Object relatedActionId = null;

        relatedActionId = resultSet.getObject(columnIndex++);

        object.setRelatedActionIdNull(resultSet.getBoolean(columnIndex++));

        if (relatedActionId != null) {

          setBeanValue(object, _DataObjectProperty.RelatedActionId, relatedActionId);
        }

        Object handler = null;

        handler = resultSet.getObject(columnIndex++);

        object.setHandlerNull(resultSet.getBoolean(columnIndex++));

        if (handler != null) {

          setBeanValue(object, _DataObjectProperty.Handler, handler);
        }

        Object icon = null;

        icon = resultSet.getObject(columnIndex++);

        object.setIconNull(resultSet.getBoolean(columnIndex++));

        if (icon != null) {

          setBeanValue(object, _DataObjectProperty.Icon, icon);
        }

        Object labelText = null;

        labelText = resultSet.getObject(columnIndex++);

        object.setLabelTextNull(resultSet.getBoolean(columnIndex++));

        if (labelText != null) {

          setBeanValue(object, _DataObjectProperty.LabelText, labelText);
        }

        Object labelKey = null;

        labelKey = resultSet.getObject(columnIndex++);

        object.setLabelKeyNull(resultSet.getBoolean(columnIndex++));

        if (labelKey != null) {

          setBeanValue(object, _DataObjectProperty.LabelKey, labelKey);
        }

        Object confirmInfo = null;

        confirmInfo = resultSet.getObject(columnIndex++);

        object.setConfirmInfoNull(resultSet.getBoolean(columnIndex++));

        if (confirmInfo != null) {

          setBeanValue(object, _DataObjectProperty.ConfirmInfo, confirmInfo);
        }

        Object confirmInfoKey = null;

        confirmInfoKey = resultSet.getObject(columnIndex++);

        object.setConfirmInfoKeyNull(resultSet.getBoolean(columnIndex++));

        if (confirmInfoKey != null) {

          setBeanValue(object, _DataObjectProperty.ConfirmInfoKey, confirmInfoKey);
        }

        Object lastModifyUser = null;

        lastModifyUser = resultSet.getObject(columnIndex++);

        object.setLastModifyUserNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyUser != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyUser, lastModifyUser);
        }

        Object lastModifyTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          lastModifyTime = resultSet.getTimestamp(columnIndex++);

        } else {
          lastModifyTime = resultSet.getObject(columnIndex++);
        }

        object.setLastModifyTimeNull(resultSet.getBoolean(columnIndex++));

        if (lastModifyTime != null) {

          setBeanValue(object, _DataObjectProperty.LastModifyTime, lastModifyTime);
        }

        Object sortIndex = null;

        sortIndex = resultSet.getObject(columnIndex++);

        object.setSortIndexNull(resultSet.getBoolean(columnIndex++));

        if (sortIndex != null) {

          setBeanValue(object, _DataObjectProperty.SortIndex, sortIndex);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object visibleScript = null;

        visibleScript = resultSet.getObject(columnIndex++);

        object.setVisibleScriptNull(resultSet.getBoolean(columnIndex++));

        if (visibleScript != null) {

          setBeanValue(object, _DataObjectProperty.VisibleScript, visibleScript);
        }

        Object menuListId = null;

        menuListId = resultSet.getObject(columnIndex++);

        object.setMenuListIdNull(resultSet.getBoolean(columnIndex++));

        if (menuListId != null) {

          setBeanValue(object, _DataObjectProperty.MenuListId, menuListId);
        }

        Object disableScript = null;

        disableScript = resultSet.getObject(columnIndex++);

        object.setDisableScriptNull(resultSet.getBoolean(columnIndex++));

        if (disableScript != null) {

          setBeanValue(object, _DataObjectProperty.DisableScript, disableScript);
        }

        Object style = null;

        style = resultSet.getObject(columnIndex++);

        object.setStyleNull(resultSet.getBoolean(columnIndex++));

        if (style != null) {

          setBeanValue(object, _DataObjectProperty.Style, style);
        }

        Object actionGroupCode = null;

        actionGroupCode = resultSet.getObject(columnIndex++);

        object.setActionGroupCodeNull(resultSet.getBoolean(columnIndex++));

        if (actionGroupCode != null) {

          setBeanValue(object, _DataObjectProperty.ActionGroupCode, actionGroupCode);
        }

        Object actionCode = null;

        actionCode = resultSet.getObject(columnIndex++);

        object.setActionCodeNull(resultSet.getBoolean(columnIndex++));

        if (actionCode != null) {

          setBeanValue(object, _DataObjectProperty.ActionCode, actionCode);
        }

        Object actionType = null;

        actionType = resultSet.getObject(columnIndex++);

        object.setActionTypeNull(resultSet.getBoolean(columnIndex++));

        if (actionType != null) {

          setBeanValue(object, _DataObjectProperty.ActionType, actionType);
        }

        Object listCode = null;

        listCode = resultSet.getObject(columnIndex++);

        object.setListCodeNull(resultSet.getBoolean(columnIndex++));

        if (listCode != null) {

          setBeanValue(object, _DataObjectProperty.ListCode, listCode);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
